{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Perceptron"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import tensorflow\n",
    "from ann.tf.perceptron import perceptron"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Training error epoch 1: 0.02\n",
      "Training error epoch 2: 0.00\n",
      "Training error epoch 3: 0.00\n",
      "Weights:\n",
      " [[ 4.29999971]\n",
      " [ 2.28999972]]\n",
      "Bias [[-5.]]\n"
     ]
    }
   ],
   "source": [
    "# Load data\n",
    "data = np.genfromtxt('https://raw.githubusercontent.com/rasbt/deep-learning-book'\n",
    "                     '/master/code/ch02_perceptron/perceptron_toydata.txt', delimiter='\\t')\n",
    "X, y = data[:, :-1], data[:, -1]\n",
    "y = y.astype(np.int)\n",
    "num_features = X.shape[1]\n",
    "\n",
    "# Initialize graph\n",
    "g = tf.Graph()\n",
    "with g.as_default() as g:\n",
    "    perceptron(num_features=num_features)\n",
    "    \n",
    "# Train perceptron\n",
    "with tf.Session(graph=g) as sess:\n",
    "    sess.run(tf.global_variables_initializer())\n",
    "    \n",
    "    for epoch in range(1, 4):\n",
    "        for example, target in zip(X, y):\n",
    "            feed_dict = {'features:0': example.reshape(-1, num_features),\n",
    "                         'targets:0': target.reshape(-1, 1)}\n",
    "            _ = sess.run('train:0', feed_dict=feed_dict)\n",
    "    \n",
    "        pred = sess.run('predict:0', feed_dict={'features:0': X})\n",
    "        train_error = np.sum(pred.reshape(-1) != y) / X.shape[0]\n",
    "        print('Training error epoch %d: %.2f' % (epoch, train_error))\n",
    "    \n",
    "    weights, bias = sess.run(['weights:0', 'bias:0'])\n",
    "    print('Weights:\\n', weights)\n",
    "    print('Bias', bias)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAD8CAYAAABjAo9vAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XlclWXe+PHPxTkICCjmUgoapqbmgiSC5rSMzYztNpZZ\nijtazZRto2M1PdnylI09bdPTmII7U2nTWL+pyZrxaZZSBMPd1LJFMMswFRCQg9fvD7BAWc5yn3Mv\n5/t+vXxNHA73/b0Pw/e+7mv5XkprjRBCCOeIMDsAIYQQxpLELoQQDiOJXQghHEYSuxBCOIwkdiGE\ncBhJ7EII4TCS2IUQwmEksQshhMNIYhdCCIdxm3HSDh066OTkZDNOLYQQtrVp06bvtNYdW3qfKYk9\nOTmZgoICM04thBC2pZT60pv3SVeMEEI4jCR2IYRwGEnsQgjhMKb0sTemurqaoqIiKisrzQ7FMqKj\no0lKSiIyMtLsUIQQNmJIYldKJQDZQH9AA1O11ut9OUZRURHx8fEkJyejlDIiLFvTWlNSUkJRURHd\nu3c3OxwhhI0Y1RXzPPCu1roPkALs8vUAlZWVtG/fXpJ6HaUU7du3lycYIYTPAm6xK6XaApcAkwG0\n1ieAE34eK9BwHEU+DyGEP4xosXcHDgFLlFKFSqlspVTs6W9SSs1QShUopQoOHTpkwGmFlVScqGHu\nWzs4erza7FCECHtGJHY3cCHwR611KlAOzDn9TVrrhVrrNK11WseOLS6csoy5c+fy9NNPB+XYmzZt\nYsCAAfTs2ZOZM2di5/1nd359jD/lfcXkpRspr/KYHY4QYc2IxF4EFGmt8+q+fp3aRC9acPvtt7No\n0SL27t3L3r17effdd80OyW+Dz23HH8alsrXoKNOXF1BZXWN2SEKErYATu9b6ILBfKdW77qXLgZ2B\nHrclawqLGT5vHd3nvM3weetYU1gc8DGXL1/OwIEDSUlJYcKECWd8f9GiRQwZMoSUlBRuuOEGjh8/\nDsD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TDSYhdCCIeRxB5kSqn7lFJaKdXB7FhCQSk1Xyn1iVJqq1LqL0qpBLNjCial1BVK\nqd1KqU+VUnPMjicUlFJdlVL/p5TaqZTaoZS6y+yYQkkp5VJKFSql/mp2LE2RxB5ESqmuwC+Ar8yO\nJYTeB/prrQcCe4D7TY4naJRSLuB/gSuBC4BblFIXmBtVSHiA+7TWFwBDgV+HyXWfchewy+wgmiOJ\nPbieBWYDYTOQobV+T2vtqftyA5BkZjxBlg58qrXep7U+AbwKjDI5pqDTWn+ttf647r9LqU1yieZG\nFRpKqSTgaiDb7FiaI4k9SJRSo4BirfUWs2Mx0VTgb2YHEUSJwP56XxcRJgnuFKVUMpAK5JkbScg8\nR21j7aTZgTRH9jwNgFLq78A5jXzrQeABarthHKe569Zav1n3ngepfWTPDWVsInSUUnHAn4G7tdbH\nzI4n2JRS1wDfaq03KaUuMzue5khiD4DW+meNva6UGgB0B7YopaC2O+JjpVS61vpgCEMMiqau+xSl\n1GTgGuBy7ez5tMVA13pfJ9W95nhKqUhqk3qu1voNs+MJkeHAdUqpq4BooI1SaqXWOtPkuM4g89hD\nQCn1BZCmtXZ8sSSl1BXAM8ClWutDZscTTEopN7UDxJdTm9DzgXFa6x2mBhZkqra1sgw4rLW+2+x4\nzFDXYv+N1voas2NpjPSxC6O9CMQD7yulNiulFpgdULDUDRLfAayldgBxldOTep3hwARgRN3veHNd\nK1ZYhLTYhRDCYaTFLoQQDiOJXQghHEYSuxBCOIwkdiGEcBhJ7EII4TCS2IUQwmEksQshhMNIYhdC\nCIf5//gVwtloCvauAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10e673a58>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "x_min = -2\n",
    "y_min = ( -(weights[0] * x_min) / weights[1]\n",
    "          -(bias[0] / weights[1]) )\n",
    "\n",
    "x_max = 4\n",
    "y_max = ( -(weights[0] * x_max) / weights[1]\n",
    "          -(bias[0] / weights[1]) )\n",
    "\n",
    "fig, ax = plt.subplots(1)\n",
    "\n",
    "ax.plot([x_min, x_max], [y_min, y_max])\n",
    "ax.scatter(X[y==0, 0], X[y==0, 1], label='class 0', marker='o')\n",
    "ax.scatter(X[y==1, 0], X[y==1, 1], label='class 1', marker='s')\n",
    "\n",
    "ax.legend(loc='upper left')\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
